package com.cuit.controller;

import com.cuit.pojo.Article;
import com.cuit.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    ArticleService articleService;
    @RequestMapping("/findAll")
    public List<Article> findAll(int page,int pageSize){
        return  articleService.findAll(page,pageSize);
    }
    @RequestMapping("/countAll")
    public int countAll(){
        return articleService.countAll();
    }
    @RequestMapping("/search")
    public List<Article> search(int page,int pageSize,String searchText){
        return articleService.search(page,pageSize,searchText);
    }
    @RequestMapping("/findArticleByUserId")
    public List<Article> findArticleByUserId(int userId,int page,int pageSize){
        return articleService.findArticleByUserId(userId,page,pageSize);
    }
    @RequestMapping("/countArticleByUserId")
    public int countArticleByUserId(){
        return articleService.countArticleByUserId();
    }
    @RequestMapping("/findArticleById")
    public Article findArticleById(int articleId){
        return articleService.findArticleById(articleId);
    }
    @RequestMapping("/likeById")
    public void likeById(int id){
        articleService.likeById(id);
    }
    @RequestMapping("/dislikeById")
    public void dislikeById(int id){
        articleService.dislikeById(id);
    }
    @RequestMapping("/insertArticle")
    public void insertArticle(int userId,String articleTitle,String articleText){
        articleService.insertArticle(userId,articleTitle,articleText);
    }
}
